<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @change="getOrderList"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
          label="订单编号"
          prop="order_number"
          min-width="100"
        ></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.order_pay === '0'"
              >未付款</el-tag
            >
            <el-tag type="danger" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            <span>{{ scope.row.create_time | dataFormate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <!-- 修改地址 -->
          <template slot-scope="">
            <el-button
              icon="el-icon-edit"
              type="primary"
              size="mini"
              @click="showAddress"
            ></el-button>
            <!-- 查看进程 -->
            <el-button
              icon="el-icon-location"
              type="success"
              size="mini"
              @click="showProgress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 修改地址弹框 -->
      <el-dialog title="修改地址" :visible.sync="adressDialog" width="50%" @close="reAddress">
        <el-form
          :model="addressForm"
          :rules="addressRules"
          ref="addressRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader
              v-model="cityValue"
              :options="cityData"
              :props="{ expandTrigger: 'hover' }"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="addressForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer">
          <el-button @click="adressDialog = false">取 消</el-button>
          <el-button type="primary" @click="adressDialog = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 查看进程弹框 -->
      <el-dialog title="查看进程" :visible.sync="progressDialog" width="50%">
        <!-- <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.timestamp"
          >
            {{ activity.content }}
          </el-timeline-item>
        </el-timeline> -->
        <span slot="footer">
          <el-button @click="progressDialog = false">取 消</el-button>
          <el-button type="primary" @click="progressDialog = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from "./citydata";
export default {
  data() {
    return {
      orderList: [],
      queryInfo: {
        query: "",
        pagesize: 10,
        pagenum: 1,
      },
      total: 0,
      adressDialog: false,
      addressForm: {
        address1: [],
        address2: "",
      },
      addressRules: {
        address1: { required: true, message: "请输入地区", trigger: "blur" },
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
      cityData,
      cityValue: [],
      progressDialog: false,
    };
  },
  methods: {
    //获取订单数据
    async getOrderList() {
      let { data: res } = await this.$http.get("orders", {
        params: {
          query: this.queryInfo.query,
          pagesize: this.queryInfo.pagesize,
          pagenum: this.queryInfo.pagenum,
        },
      });
      console.log(res);
      if (res.meta.status != 200) return this.$message.error("获取数据失败");
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    //显示多少条
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrderList();
    },
    //当前第几页
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrderList();
    },
    //修改地址
    showAddress() {
      this.adressDialog = true;
    },
    handleChange() {},
    //查看进程
    showProgress() {
      // let {data:res} =  await this.$http.get('kuaidi/1')
      // console.log(res)
      // if(res.meta.status != 200) return this.$message.error("获取数据失败")
      this.progressDialog = true;
    },
    //重置表单
    reAddress(){
      this.cityValue = []
      this.$refs.addressRef.resetFields()
    }
  },
  created() {
    this.getOrderList();
  },
};
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 20px;
  font-size: 12px;
}
.el-form {
  text-align: left;
}
</style>